

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.ico">
  <link rel="icon" href="/img/favicon.ico">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content>
  <meta name="author" content="kinzun">
  <meta name="keywords" content>
  <meta name="keywords" content="Python">
<meta property="og:type" content="article">
<meta property="og:title" content="Python base 速写">
<meta property="og:url" content="https://kinzun.github.io/2018/09/26/python-base速写/index.html">
<meta property="og:site_name" content="kinzun">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://kinzun.github.io/images/fedora00001.png">
<meta property="og:updated_time" content="2018-10-04T08:12:40.678Z">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Python base 速写">
<meta name="twitter:image" content="https://kinzun.github.io/images/fedora00001.png">
  
  <title>Python base 速写 - kinzun</title>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css">


  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css">
  <link rel="stylesheet" href="/lib/hint/hint.min.css">

  
    
    
      
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css">
    
  

  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">

<link rel="stylesheet" href="/css/main.css">

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"kinzun.github.io","root":"/","version":"1.8.12","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname"}},"search_path":"/local-search.xml"};
  </script>
  <script src="/js/utils.js"></script>
  <script src="/js/color-schema.js"></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>kinzun</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="Python base 速写">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2018-09-26 08:28" pubdate>
        2018年9月26日 早上
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      40k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      125 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Python base 速写</h1>
            
            <div class="markdown-body">
              <p><img src="/images/fedora00001.png" srcset="/img/loading.gif" lazyload alt="u11231"></p>
 <a id="more"></a>
<figure class="highlight"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br><span class="line">552</span><br><span class="line">553</span><br><span class="line">554</span><br><span class="line">555</span><br><span class="line">556</span><br><span class="line">557</span><br><span class="line">558</span><br><span class="line">559</span><br><span class="line">560</span><br><span class="line">561</span><br><span class="line">562</span><br><span class="line">563</span><br><span class="line">564</span><br><span class="line">565</span><br><span class="line">566</span><br><span class="line">567</span><br><span class="line">568</span><br><span class="line">569</span><br><span class="line">570</span><br><span class="line">571</span><br><span class="line">572</span><br><span class="line">573</span><br><span class="line">574</span><br><span class="line">575</span><br><span class="line">576</span><br><span class="line">577</span><br><span class="line">578</span><br><span class="line">579</span><br><span class="line">580</span><br><span class="line">581</span><br><span class="line">582</span><br><span class="line">583</span><br><span class="line">584</span><br><span class="line">585</span><br><span class="line">586</span><br><span class="line">587</span><br><span class="line">588</span><br><span class="line">589</span><br><span class="line">590</span><br><span class="line">591</span><br><span class="line">592</span><br><span class="line">593</span><br><span class="line">594</span><br><span class="line">595</span><br><span class="line">596</span><br><span class="line">597</span><br><span class="line">598</span><br><span class="line">599</span><br><span class="line">600</span><br><span class="line">601</span><br><span class="line">602</span><br><span class="line">603</span><br><span class="line">604</span><br><span class="line">605</span><br><span class="line">606</span><br><span class="line">607</span><br><span class="line">608</span><br><span class="line">609</span><br><span class="line">610</span><br><span class="line">611</span><br><span class="line">612</span><br><span class="line">613</span><br><span class="line">614</span><br><span class="line">615</span><br><span class="line">616</span><br><span class="line">617</span><br><span class="line">618</span><br><span class="line">619</span><br><span class="line">620</span><br><span class="line">621</span><br><span class="line">622</span><br><span class="line">623</span><br><span class="line">624</span><br><span class="line">625</span><br><span class="line">626</span><br><span class="line">627</span><br><span class="line">628</span><br><span class="line">629</span><br><span class="line">630</span><br><span class="line">631</span><br><span class="line">632</span><br><span class="line">633</span><br><span class="line">634</span><br><span class="line">635</span><br><span class="line">636</span><br><span class="line">637</span><br><span class="line">638</span><br><span class="line">639</span><br><span class="line">640</span><br><span class="line">641</span><br><span class="line">642</span><br><span class="line">643</span><br><span class="line">644</span><br><span class="line">645</span><br><span class="line">646</span><br><span class="line">647</span><br><span class="line">648</span><br><span class="line">649</span><br><span class="line">650</span><br><span class="line">651</span><br><span class="line">652</span><br><span class="line">653</span><br><span class="line">654</span><br><span class="line">655</span><br><span class="line">656</span><br><span class="line">657</span><br><span class="line">658</span><br><span class="line">659</span><br><span class="line">660</span><br><span class="line">661</span><br><span class="line">662</span><br><span class="line">663</span><br><span class="line">664</span><br><span class="line">665</span><br><span class="line">666</span><br><span class="line">667</span><br><span class="line">668</span><br><span class="line">669</span><br><span class="line">670</span><br><span class="line">671</span><br><span class="line">672</span><br><span class="line">673</span><br><span class="line">674</span><br><span class="line">675</span><br><span class="line">676</span><br><span class="line">677</span><br><span class="line">678</span><br><span class="line">679</span><br><span class="line">680</span><br><span class="line">681</span><br><span class="line">682</span><br><span class="line">683</span><br><span class="line">684</span><br><span class="line">685</span><br><span class="line">686</span><br><span class="line">687</span><br><span class="line">688</span><br><span class="line">689</span><br><span class="line">690</span><br><span class="line">691</span><br><span class="line">692</span><br><span class="line">693</span><br><span class="line">694</span><br><span class="line">695</span><br><span class="line">696</span><br><span class="line">697</span><br><span class="line">698</span><br><span class="line">699</span><br><span class="line">700</span><br><span class="line">701</span><br><span class="line">702</span><br><span class="line">703</span><br><span class="line">704</span><br><span class="line">705</span><br><span class="line">706</span><br><span class="line">707</span><br><span class="line">708</span><br><span class="line">709</span><br><span class="line">710</span><br><span class="line">711</span><br><span class="line">712</span><br><span class="line">713</span><br><span class="line">714</span><br><span class="line">715</span><br><span class="line">716</span><br><span class="line">717</span><br><span class="line">718</span><br><span class="line">719</span><br><span class="line">720</span><br><span class="line">721</span><br><span class="line">722</span><br><span class="line">723</span><br><span class="line">724</span><br><span class="line">725</span><br><span class="line">726</span><br><span class="line">727</span><br><span class="line">728</span><br><span class="line">729</span><br><span class="line">730</span><br><span class="line">731</span><br><span class="line">732</span><br><span class="line">733</span><br><span class="line">734</span><br><span class="line">735</span><br><span class="line">736</span><br><span class="line">737</span><br><span class="line">738</span><br><span class="line">739</span><br><span class="line">740</span><br><span class="line">741</span><br><span class="line">742</span><br><span class="line">743</span><br><span class="line">744</span><br><span class="line">745</span><br><span class="line">746</span><br><span class="line">747</span><br><span class="line">748</span><br><span class="line">749</span><br><span class="line">750</span><br><span class="line">751</span><br><span class="line">752</span><br><span class="line">753</span><br><span class="line">754</span><br><span class="line">755</span><br><span class="line">756</span><br><span class="line">757</span><br><span class="line">758</span><br><span class="line">759</span><br><span class="line">760</span><br><span class="line">761</span><br><span class="line">762</span><br><span class="line">763</span><br><span class="line">764</span><br><span class="line">765</span><br><span class="line">766</span><br><span class="line">767</span><br><span class="line">768</span><br><span class="line">769</span><br><span class="line">770</span><br><span class="line">771</span><br><span class="line">772</span><br><span class="line">773</span><br><span class="line">774</span><br><span class="line">775</span><br><span class="line">776</span><br><span class="line">777</span><br><span class="line">778</span><br><span class="line">779</span><br><span class="line">780</span><br><span class="line">781</span><br><span class="line">782</span><br><span class="line">783</span><br><span class="line">784</span><br><span class="line">785</span><br><span class="line">786</span><br><span class="line">787</span><br><span class="line">788</span><br><span class="line">789</span><br><span class="line">790</span><br><span class="line">791</span><br><span class="line">792</span><br><span class="line">793</span><br><span class="line">794</span><br><span class="line">795</span><br><span class="line">796</span><br><span class="line">797</span><br><span class="line">798</span><br><span class="line">799</span><br><span class="line">800</span><br><span class="line">801</span><br><span class="line">802</span><br><span class="line">803</span><br><span class="line">804</span><br><span class="line">805</span><br><span class="line">806</span><br><span class="line">807</span><br><span class="line">808</span><br><span class="line">809</span><br><span class="line">810</span><br><span class="line">811</span><br><span class="line">812</span><br><span class="line">813</span><br><span class="line">814</span><br><span class="line">815</span><br><span class="line">816</span><br><span class="line">817</span><br><span class="line">818</span><br><span class="line">819</span><br><span class="line">820</span><br><span class="line">821</span><br><span class="line">822</span><br><span class="line">823</span><br><span class="line">824</span><br><span class="line">825</span><br><span class="line">826</span><br><span class="line">827</span><br><span class="line">828</span><br><span class="line">829</span><br><span class="line">830</span><br><span class="line">831</span><br><span class="line">832</span><br><span class="line">833</span><br><span class="line">834</span><br><span class="line">835</span><br><span class="line">836</span><br><span class="line">837</span><br><span class="line">838</span><br><span class="line">839</span><br><span class="line">840</span><br><span class="line">841</span><br><span class="line">842</span><br><span class="line">843</span><br><span class="line">844</span><br><span class="line">845</span><br><span class="line">846</span><br><span class="line">847</span><br><span class="line">848</span><br><span class="line">849</span><br><span class="line">850</span><br><span class="line">851</span><br><span class="line">852</span><br><span class="line">853</span><br><span class="line">854</span><br><span class="line">855</span><br><span class="line">856</span><br><span class="line">857</span><br><span class="line">858</span><br><span class="line">859</span><br><span class="line">860</span><br><span class="line">861</span><br><span class="line">862</span><br><span class="line">863</span><br><span class="line">864</span><br><span class="line">865</span><br><span class="line">866</span><br><span class="line">867</span><br><span class="line">868</span><br><span class="line">869</span><br><span class="line">870</span><br><span class="line">871</span><br><span class="line">872</span><br><span class="line">873</span><br><span class="line">874</span><br><span class="line">875</span><br><span class="line">876</span><br><span class="line">877</span><br><span class="line">878</span><br><span class="line">879</span><br><span class="line">880</span><br><span class="line">881</span><br><span class="line">882</span><br><span class="line">883</span><br><span class="line">884</span><br><span class="line">885</span><br><span class="line">886</span><br><span class="line">887</span><br><span class="line">888</span><br><span class="line">889</span><br><span class="line">890</span><br><span class="line">891</span><br><span class="line">892</span><br><span class="line">893</span><br><span class="line">894</span><br><span class="line">895</span><br><span class="line">896</span><br><span class="line">897</span><br><span class="line">898</span><br><span class="line">899</span><br><span class="line">900</span><br><span class="line">901</span><br><span class="line">902</span><br><span class="line">903</span><br><span class="line">904</span><br><span class="line">905</span><br><span class="line">906</span><br><span class="line">907</span><br><span class="line">908</span><br><span class="line">909</span><br><span class="line">910</span><br><span class="line">911</span><br><span class="line">912</span><br><span class="line">913</span><br><span class="line">914</span><br><span class="line">915</span><br><span class="line">916</span><br><span class="line">917</span><br><span class="line">918</span><br><span class="line">919</span><br><span class="line">920</span><br><span class="line">921</span><br><span class="line">922</span><br><span class="line">923</span><br><span class="line">924</span><br><span class="line">925</span><br><span class="line">926</span><br><span class="line">927</span><br><span class="line">928</span><br><span class="line">929</span><br><span class="line">930</span><br><span class="line">931</span><br><span class="line">932</span><br><span class="line">933</span><br><span class="line">934</span><br><span class="line">935</span><br><span class="line">936</span><br><span class="line">937</span><br><span class="line">938</span><br><span class="line">939</span><br><span class="line">940</span><br><span class="line">941</span><br><span class="line">942</span><br><span class="line">943</span><br><span class="line">944</span><br><span class="line">945</span><br><span class="line">946</span><br><span class="line">947</span><br><span class="line">948</span><br><span class="line">949</span><br><span class="line">950</span><br><span class="line">951</span><br><span class="line">952</span><br><span class="line">953</span><br><span class="line">954</span><br><span class="line">955</span><br><span class="line">956</span><br><span class="line">957</span><br><span class="line">958</span><br><span class="line">959</span><br><span class="line">960</span><br><span class="line">961</span><br><span class="line">962</span><br><span class="line">963</span><br><span class="line">964</span><br><span class="line">965</span><br><span class="line">966</span><br><span class="line">967</span><br><span class="line">968</span><br><span class="line">969</span><br><span class="line">970</span><br><span class="line">971</span><br><span class="line">972</span><br><span class="line">973</span><br><span class="line">974</span><br><span class="line">975</span><br><span class="line">976</span><br><span class="line">977</span><br><span class="line">978</span><br><span class="line">979</span><br><span class="line">980</span><br><span class="line">981</span><br><span class="line">982</span><br><span class="line">983</span><br><span class="line">984</span><br><span class="line">985</span><br><span class="line">986</span><br><span class="line">987</span><br><span class="line">988</span><br><span class="line">989</span><br><span class="line">990</span><br><span class="line">991</span><br><span class="line">992</span><br><span class="line">993</span><br><span class="line">994</span><br><span class="line">995</span><br><span class="line">996</span><br><span class="line">997</span><br><span class="line">998</span><br><span class="line">999</span><br><span class="line">1000</span><br><span class="line">1001</span><br><span class="line">1002</span><br><span class="line">1003</span><br><span class="line">1004</span><br><span class="line">1005</span><br><span class="line">1006</span><br><span class="line">1007</span><br><span class="line">1008</span><br><span class="line">1009</span><br><span class="line">1010</span><br><span class="line">1011</span><br><span class="line">1012</span><br><span class="line">1013</span><br><span class="line">1014</span><br><span class="line">1015</span><br><span class="line">1016</span><br><span class="line">1017</span><br><span class="line">1018</span><br><span class="line">1019</span><br><span class="line">1020</span><br><span class="line">1021</span><br><span class="line">1022</span><br><span class="line">1023</span><br><span class="line">1024</span><br><span class="line">1025</span><br><span class="line">1026</span><br><span class="line">1027</span><br><span class="line">1028</span><br><span class="line">1029</span><br><span class="line">1030</span><br><span class="line">1031</span><br><span class="line">1032</span><br><span class="line">1033</span><br><span class="line">1034</span><br><span class="line">1035</span><br><span class="line">1036</span><br><span class="line">1037</span><br><span class="line">1038</span><br><span class="line">1039</span><br><span class="line">1040</span><br><span class="line">1041</span><br><span class="line">1042</span><br><span class="line">1043</span><br><span class="line">1044</span><br><span class="line">1045</span><br><span class="line">1046</span><br><span class="line">1047</span><br><span class="line">1048</span><br><span class="line">1049</span><br><span class="line">1050</span><br><span class="line">1051</span><br><span class="line">1052</span><br><span class="line">1053</span><br><span class="line">1054</span><br><span class="line">1055</span><br><span class="line">1056</span><br><span class="line">1057</span><br><span class="line">1058</span><br><span class="line">1059</span><br><span class="line">1060</span><br><span class="line">1061</span><br><span class="line">1062</span><br><span class="line">1063</span><br><span class="line">1064</span><br><span class="line">1065</span><br><span class="line">1066</span><br><span class="line">1067</span><br><span class="line">1068</span><br><span class="line">1069</span><br><span class="line">1070</span><br><span class="line">1071</span><br><span class="line">1072</span><br><span class="line">1073</span><br><span class="line">1074</span><br><span class="line">1075</span><br><span class="line">1076</span><br><span class="line">1077</span><br><span class="line">1078</span><br><span class="line">1079</span><br><span class="line">1080</span><br><span class="line">1081</span><br><span class="line">1082</span><br><span class="line">1083</span><br><span class="line">1084</span><br><span class="line">1085</span><br><span class="line">1086</span><br><span class="line">1087</span><br><span class="line">1088</span><br><span class="line">1089</span><br><span class="line">1090</span><br><span class="line">1091</span><br><span class="line">1092</span><br><span class="line">1093</span><br><span class="line">1094</span><br><span class="line">1095</span><br><span class="line">1096</span><br><span class="line">1097</span><br><span class="line">1098</span><br><span class="line">1099</span><br><span class="line">1100</span><br><span class="line">1101</span><br><span class="line">1102</span><br><span class="line">1103</span><br><span class="line">1104</span><br><span class="line">1105</span><br><span class="line">1106</span><br><span class="line">1107</span><br><span class="line">1108</span><br><span class="line">1109</span><br><span class="line">1110</span><br><span class="line">1111</span><br><span class="line">1112</span><br><span class="line">1113</span><br><span class="line">1114</span><br><span class="line">1115</span><br><span class="line">1116</span><br><span class="line">1117</span><br><span class="line">1118</span><br><span class="line">1119</span><br><span class="line">1120</span><br><span class="line">1121</span><br><span class="line">1122</span><br><span class="line">1123</span><br><span class="line">1124</span><br><span class="line">1125</span><br><span class="line">1126</span><br><span class="line">1127</span><br><span class="line">1128</span><br><span class="line">1129</span><br><span class="line">1130</span><br><span class="line">1131</span><br><span class="line">1132</span><br><span class="line">1133</span><br><span class="line">1134</span><br><span class="line">1135</span><br><span class="line">1136</span><br><span class="line">1137</span><br><span class="line">1138</span><br><span class="line">1139</span><br><span class="line">1140</span><br><span class="line">1141</span><br><span class="line">1142</span><br><span class="line">1143</span><br><span class="line">1144</span><br><span class="line">1145</span><br><span class="line">1146</span><br><span class="line">1147</span><br><span class="line">1148</span><br><span class="line">1149</span><br><span class="line">1150</span><br><span class="line">1151</span><br><span class="line">1152</span><br><span class="line">1153</span><br><span class="line">1154</span><br><span class="line">1155</span><br><span class="line">1156</span><br><span class="line">1157</span><br><span class="line">1158</span><br><span class="line">1159</span><br><span class="line">1160</span><br><span class="line">1161</span><br><span class="line">1162</span><br><span class="line">1163</span><br><span class="line">1164</span><br><span class="line">1165</span><br><span class="line">1166</span><br><span class="line">1167</span><br><span class="line">1168</span><br><span class="line">1169</span><br><span class="line">1170</span><br><span class="line">1171</span><br><span class="line">1172</span><br><span class="line">1173</span><br><span class="line">1174</span><br><span class="line">1175</span><br><span class="line">1176</span><br><span class="line">1177</span><br><span class="line">1178</span><br><span class="line">1179</span><br><span class="line">1180</span><br><span class="line">1181</span><br><span class="line">1182</span><br><span class="line">1183</span><br><span class="line">1184</span><br><span class="line">1185</span><br><span class="line">1186</span><br><span class="line">1187</span><br><span class="line">1188</span><br><span class="line">1189</span><br><span class="line">1190</span><br><span class="line">1191</span><br><span class="line">1192</span><br><span class="line">1193</span><br><span class="line">1194</span><br><span class="line">1195</span><br><span class="line">1196</span><br><span class="line">1197</span><br><span class="line">1198</span><br><span class="line">1199</span><br><span class="line">1200</span><br><span class="line">1201</span><br><span class="line">1202</span><br><span class="line">1203</span><br><span class="line">1204</span><br><span class="line">1205</span><br><span class="line">1206</span><br><span class="line">1207</span><br><span class="line">1208</span><br><span class="line">1209</span><br><span class="line">1210</span><br><span class="line">1211</span><br><span class="line">1212</span><br><span class="line">1213</span><br><span class="line">1214</span><br><span class="line">1215</span><br><span class="line">1216</span><br><span class="line">1217</span><br><span class="line">1218</span><br><span class="line">1219</span><br><span class="line">1220</span><br><span class="line">1221</span><br><span class="line">1222</span><br><span class="line">1223</span><br><span class="line">1224</span><br><span class="line">1225</span><br><span class="line">1226</span><br><span class="line">1227</span><br><span class="line">1228</span><br><span class="line">1229</span><br><span class="line">1230</span><br><span class="line">1231</span><br><span class="line">1232</span><br><span class="line">1233</span><br><span class="line">1234</span><br><span class="line">1235</span><br><span class="line">1236</span><br><span class="line">1237</span><br><span class="line">1238</span><br><span class="line">1239</span><br><span class="line">1240</span><br><span class="line">1241</span><br><span class="line">1242</span><br><span class="line">1243</span><br><span class="line">1244</span><br><span class="line">1245</span><br><span class="line">1246</span><br><span class="line">1247</span><br><span class="line">1248</span><br><span class="line">1249</span><br><span class="line">1250</span><br><span class="line">1251</span><br><span class="line">1252</span><br><span class="line">1253</span><br><span class="line">1254</span><br><span class="line">1255</span><br><span class="line">1256</span><br><span class="line">1257</span><br><span class="line">1258</span><br><span class="line">1259</span><br><span class="line">1260</span><br><span class="line">1261</span><br><span class="line">1262</span><br><span class="line">1263</span><br><span class="line">1264</span><br><span class="line">1265</span><br><span class="line">1266</span><br><span class="line">1267</span><br><span class="line">1268</span><br><span class="line">1269</span><br><span class="line">1270</span><br><span class="line">1271</span><br><span class="line">1272</span><br><span class="line">1273</span><br><span class="line">1274</span><br><span class="line">1275</span><br><span class="line">1276</span><br><span class="line">1277</span><br><span class="line">1278</span><br><span class="line">1279</span><br><span class="line">1280</span><br><span class="line">1281</span><br><span class="line">1282</span><br><span class="line">1283</span><br><span class="line">1284</span><br><span class="line">1285</span><br><span class="line">1286</span><br><span class="line">1287</span><br><span class="line">1288</span><br><span class="line">1289</span><br><span class="line">1290</span><br><span class="line">1291</span><br><span class="line">1292</span><br><span class="line">1293</span><br><span class="line">1294</span><br><span class="line">1295</span><br><span class="line">1296</span><br><span class="line">1297</span><br><span class="line">1298</span><br><span class="line">1299</span><br><span class="line">1300</span><br><span class="line">1301</span><br><span class="line">1302</span><br><span class="line">1303</span><br><span class="line">1304</span><br><span class="line">1305</span><br><span class="line">1306</span><br><span class="line">1307</span><br><span class="line">1308</span><br><span class="line">1309</span><br><span class="line">1310</span><br><span class="line">1311</span><br><span class="line">1312</span><br><span class="line">1313</span><br><span class="line">1314</span><br><span class="line">1315</span><br><span class="line">1316</span><br><span class="line">1317</span><br><span class="line">1318</span><br><span class="line">1319</span><br><span class="line">1320</span><br><span class="line">1321</span><br><span class="line">1322</span><br><span class="line">1323</span><br><span class="line">1324</span><br><span class="line">1325</span><br><span class="line">1326</span><br><span class="line">1327</span><br><span class="line">1328</span><br><span class="line">1329</span><br><span class="line">1330</span><br><span class="line">1331</span><br><span class="line">1332</span><br><span class="line">1333</span><br><span class="line">1334</span><br><span class="line">1335</span><br><span class="line">1336</span><br><span class="line">1337</span><br><span class="line">1338</span><br><span class="line">1339</span><br><span class="line">1340</span><br><span class="line">1341</span><br><span class="line">1342</span><br><span class="line">1343</span><br><span class="line">1344</span><br><span class="line">1345</span><br><span class="line">1346</span><br><span class="line">1347</span><br><span class="line">1348</span><br><span class="line">1349</span><br><span class="line">1350</span><br><span class="line">1351</span><br><span class="line">1352</span><br><span class="line">1353</span><br><span class="line">1354</span><br><span class="line">1355</span><br><span class="line">1356</span><br><span class="line">1357</span><br><span class="line">1358</span><br><span class="line">1359</span><br><span class="line">1360</span><br><span class="line">1361</span><br><span class="line">1362</span><br><span class="line">1363</span><br><span class="line">1364</span><br><span class="line">1365</span><br><span class="line">1366</span><br><span class="line">1367</span><br><span class="line">1368</span><br><span class="line">1369</span><br><span class="line">1370</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"># _*_ coding: utf-8 _*_<br><br>"""类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算"""<br><br>#-- 寻求帮助:<br>    dir(obj)            # 简单的列出对象obj所包含的方法名称，返回一个字符串列表<br>    help(obj.func)      # 查询obj.func的具体介绍和用法<br>    <br>#-- 测试类型的三种方法，推荐第三种<br>    if type(L) == type([]):<br>        print("L is list")<br>    if type(L) == list:<br>        print("L is list")<br>    if isinstance(L, list):<br>        print("L is list")<br><br>        <br>#-- Python数据类型：哈希类型、不可哈希类型<br>    # 哈希类型，即在原地不能改变的变量类型，不可变类型。可利用hash函数查看其hash值，也可以作为字典的key<br>    "数字类型：int, float, decimal.Decimal, fractions.Fraction, complex"<br>    "字符串类型：str, bytes"<br>    "元组：tuple"<br>    "冻结集合：frozenset"<br>    "布尔类型：True, False"<br>    "None"<br>    # 不可hash类型：原地可变类型：list、dict和set。它们不可以作为字典的key。<br><br>#-- 数字常量<br>    1234, -1234, 0, 999999999                    # 整数<br>    1.23, 1., 3.14e-10, 4E210, 4.0e+210          # 浮点数<br>    0o177, 0x9ff, 0X9FF, 0b101010                # 八进制、十六进制、二进制数字<br>    3+4j, 3.0+4.0j, 3J                           # 复数常量，也可以用complex(real, image)来创建<br>    hex(I), oct(I), bin(I)                       # 将十进制数转化为十六进制、八进制、二进制表示的“字符串”<br>    int(string, base)                            # 将字符串转化为整数，base为进制数<br>    # 2.x中，有两种整数类型：一般整数（32位）和长整数（无穷精度）。可以用l或L结尾，迫使一般整数成为长整数<br>    float('inf'), float('-inf'), float('nan')    # 无穷大, 无穷小, 非数<br>    <br>#-- 数字的表达式操作符<br>    yield x                                      # 生成器函数发送协议<br>    lambda args: expression                      # 生成匿名函数<br>    x if y else z                                # 三元选择表达式<br>    x and y, x or y, not x                       # 逻辑与、逻辑或、逻辑非<br>    x in y, x not in y                           # 成员对象测试<br>    x is y, x is not y                           # 对象实体测试<br>    x&lt;y, x&lt;=y, x&gt;y, x&gt;=y, x==y, x!=y             # 大小比较，集合子集或超集值相等性操作符<br>    1 &lt; a &lt; 3                                    # Python中允许连续比较<br>    x|y, x&amp;y, x^y                                # 位或、位与、位异或<br>    x&lt;&lt;y, x&gt;&gt;y                                   # 位操作：x左移、右移y位<br>    +, -, *, /, //, %, **                        # 真除法、floor除法：返回不大于真除法结果的整数值、取余、幂运算<br>    -x, +x, ~x                                   # 一元减法、识别、按位求补（取反）<br>    x[i], x[i:j:k]                               # 索引、分片<br>    int(3.14), float(3)                          # 强制类型转换<br>    <br>#-- 整数可以利用bit_length函数测试所占的位数<br>    a = 1;       a.bit_length()    # 1<br>    a = 1024;    a.bit_length()    # 11<br>    <br>#-- repr和str显示格式的区别<br>    """<br>    repr格式：默认的交互模式回显，产生的结果看起来它们就像是代码。<br>    str格式：打印语句，转化成一种对用户更加友好的格式。<br>    """<br>    <br>#-- 数字相关的模块<br>    # math模块<br>    # Decimal模块：小数模块<br>        import decimal<br>        from decimal import Decimal<br>        Decimal("0.01") + Decimal("0.02")        # 返回Decimal("0.03")<br>        decimal.getcontext().prec = 4            # 设置全局精度为4 即小数点后边4位<br>    # Fraction模块：分数模块<br>        from fractions import Fraction<br>        x = Fraction(4, 6)                       # 分数类型 4/6<br>        x = Fraction("0.25")                     # 分数类型 1/4 接收字符串类型的参数<br><br>#-- 集合set<br>    """<br>    set是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素。<br>    set支持union(联合), intersection(交), difference(差)和symmetric difference(对称差集)等数学运算。<br>    set支持x in set, len(set), for x in set。<br>    set不记录元素位置或者插入点, 因此不支持indexing, slicing, 或其它类序列的操作<br>    """<br>    s = set([3,5,9,10])                          # 创建一个数值集合，返回&#123;3, 5, 9, 10&#125;<br>    t = set("Hello")                             # 创建一个字符的集合，返回&#123;'l', 'H', 'e', 'o'&#125;<br>    a = t | s;    t.union(s)                     # t 和 s的并集<br>    b = t &amp; s;    t.intersection(s)              # t 和 s的交集<br>    c = t – s;    t.difference(s)                # 求差集（项在t中, 但不在s中）<br>    d = t ^ s;    t.symmetric_difference(s)      # 对称差集（项在t或s中, 但不会同时出现在二者中）<br>    t.add('x');   t.remove('H')                  # 增加/删除一个item<br>    s.update([10,37,42])                         # 利用[......]更新s集合<br>    x in s,  x not in s                          # 集合中是否存在某个值<br>    s.issubset(t);      s &lt;= t                   # 测试是否 s 中的每一个元素都在 t 中<br>    s.issuperset(t);    s &gt;= t                   # 测试是否 t 中的每一个元素都在 s 中 <br>    s.copy(); <br>    s.discard(x);                                # 删除s中x<br>    s.clear()                                    # 清空s<br>    &#123;x**2 for x in [1, 2, 3, 4]&#125;                 # 集合解析，结果：&#123;16, 1, 4, 9&#125;<br>    &#123;x for x in 'spam'&#125;                          # 集合解析，结果：&#123;'a', 'p', 's', 'm'&#125;<br>    <br>#-- 集合frozenset，不可变对象<br>    """<br>    set是可变对象，即不存在hash值，不能作为字典的键值。同样的还有list等(tuple是可以作为字典key的)<br>    frozenset是不可变对象，即存在hash值，可作为字典的键值<br>    frozenset对象没有add、remove等方法，但有union/intersection/difference等方法<br>    """<br>    a = set([1, 2, 3])<br>    b = set()<br>    b.add(a)                     # error: set是不可哈希类型<br>    b.add(frozenset(a))          # ok，将set变为frozenset，可哈希<br><br>#-- 布尔类型bool<br>    type(True)                   # 返回&lt;class 'bool'&gt;<br>    isinstance(False, int)       # bool类型属于整型，所以返回True<br>    True == 1; True is 1         # 输出(True, False)<br>    <br>#-- 动态类型简介<br>    """<br>    变量名通过引用，指向对象。<br>    Python中的“类型”属于对象，而不是变量，每个对象都包含有头部信息，比如"类型标示符" "引用计数器"等<br>    """<br>    #共享引用及在原处修改：对于可变对象，要注意尽量不要共享引用！<br>    #共享引用和相等测试：<br>        L = [1], M = [1], L is M            # 返回False<br>        L = M = [1, 2, 3], L is M           # 返回True，共享引用<br>    #增强赋值和共享引用：普通+号会生成新的对象，而增强赋值+=会在原处修改<br>        L = M = [1, 2]<br>        L = L + [3, 4]                      # L = [1, 2, 3, 4], M = [1, 2]<br>        L += [3, 4]                         # L = [1, 2, 3, 4], M = [1, 2, 3, 4]<br><br>#-- 常见字符串常量和表达式<br>    S = ''                                  # 空字符串<br>    S = "spam’s"                            # 双引号和单引号相同<br>    S = "s\np\ta\x00m"                      # 转义字符<br>    S = """spam"""                          # 三重引号字符串，一般用于函数说明<br>    S = r'\temp'                            # Raw字符串，不会进行转义，抑制转义<br>    S = b'Spam'                             # Python3中的字节字符串<br>    S = u'spam'                             # Python2.6中的Unicode字符串<br>    s1+s2, s1*3, s[i], s[i:j], len(s)       # 字符串操作<br>    'a %s parrot' % 'kind'                  # 字符串格式化表达式<br>    'a &#123;1&#125; &#123;0&#125; parrot'.format('kind', 'red')# 字符串格式化方法<br>    for x in s: print(x)                    # 字符串迭代，成员关系<br>    [x*2 for x in s]                        # 字符串列表解析<br>    ','.join(['a', 'b', 'c'])               # 字符串输出，结果：a,b,c<br>    <br>#-- 内置str处理函数：<br>    str1 = "stringobject"<br>    str1.upper(); str1.lower(); str1.swapcase(); str1.capitalize(); str1.title()        # 全部大写，全部小写、大小写转换，首字母大写，每个单词的首字母都大写<br>    str1.ljust(width)                       # 获取固定长度，左对齐，右边不够用空格补齐<br>    str1.rjust(width)                       # 获取固定长度，右对齐，左边不够用空格补齐<br>    str1.center(width)                      # 获取固定长度，中间对齐，两边不够用空格补齐<br>    str1.zfill(width)                       # 获取固定长度，右对齐，左边不足用0补齐<br>    str1.find('t',start,end)                # 查找字符串，可以指定起始及结束位置搜索<br>    str1.rfind('t')                         # 从右边开始查找字符串<br>    str1.count('t')                         # 查找字符串出现的次数<br>    #上面所有方法都可用index代替，不同的是使用index查找不到会抛异常，而find返回-1<br>    str1.replace('old','new')               # 替换函数，替换old为new，参数中可以指定maxReplaceTimes，即替换指定次数的old为new<br>    str1.strip();                           # 默认删除空白符<br>    str1.strip('d');                        # 删除str1字符串中开头、结尾处，位于 d 删除序列的字符<br>    str1.lstrip();<br>    str1.lstrip('d');                       # 删除str1字符串中开头处，位于 d 删除序列的字符<br>    str1.rstrip();<br>    str1.rstrip('d')                        # 删除str1字符串中结尾处，位于 d 删除序列的字符<br>    str1.startswith('start')                # 是否以start开头<br>    str1.endswith('end')                    # 是否以end结尾<br>    str1.isalnum(); str1.isalpha(); str1.isdigit(); str1.islower(); str1.isupper()      # 判断字符串是否全为字符、数字、小写、大写<br><br>#-- 三重引号编写多行字符串块，并且在代码折行处嵌入换行字符\n<br>    mantra = """hello world<br>            hello python<br>            hello my friend"""<br>    # mantra为"""hello world \n hello python \n hello my friend"""<br>    <br>#-- 索引和分片：<br>    S[0], S[len(S)–1], S[-1]                # 索引<br>    S[1:3], S[1:], S[:-1], S[1:10:2]        # 分片，第三个参数指定步长，如`S[1:10:2]`是从1位到10位没隔2位获取一个字符。<br><br>#-- 字符串转换工具：<br>    int('42'), str(42)                      # 返回(42, '42')<br>    float('4.13'), str(4.13)                # 返回(4.13, '4.13')<br>    ord('s'), chr(115)                      # 返回(115, 's')<br>    int('1001', 2)                          # 将字符串作为二进制数字，转化为数字，返回9<br>    bin(13), oct(13), hex(13)               # 将整数转化为二进制/八进制/十六进制字符串，返回('0b1101', '015', '0xd')<br>    <br>#-- 另类字符串连接<br>    name = "wang" "hong"                    # 单行，name = "wanghong"<br>    name = "wang" \<br>            "hong"                          # 多行，name = "wanghong"<br><br>#-- Python中的字符串格式化实现1--字符串格式化表达式<br>    """<br>    基于C语言的'print'模型，并且在大多数的现有的语言中使用。<br>    通用结构：%[(name)][flag][width].[precision]typecode<br>    """<br>    "this is %d %s bird" % (1, 'dead')                          # 一般的格式化表达式<br>    "%s---%s---%s" % (42, 3.14, [1, 2, 3])                      # 字符串输出：'42---3.14---[1, 2, 3]'<br>    "%d...%6d...%-6d...%06d" % (1234, 1234, 1234, 1234)         # 对齐方式及填充："1234...  1234...1234  ...001234"<br>    x = 1.23456789<br>    "%e | %f | %g" % (x, x, x)                                  # 对齐方式："1.234568e+00 | 1.234568 | 1.23457"<br>    "%6.2f*%-6.2f*%06.2f*%+6.2f" % (x, x, x, x)                 # 对齐方式：'  1.23*1.23  *001.23* +1.23'<br>    "%(name1)d---%(name2)s" % &#123;"name1":23, "name2":"value2"&#125;    # 基于字典的格式化表达式<br>    "%(name)s is %(age)d" % vars()                              # vars()函数调用返回一个字典，包含了所有本函数调用时存在的变量<br>    <br>#-- Python中的字符串格式化实现2--字符串格式化调用方法<br>    # 普通调用<br>    "&#123;0&#125;, &#123;1&#125; and &#123;2&#125;".format('spam', 'ham', 'eggs')            # 基于位置的调用<br>    "&#123;motto&#125; and &#123;pork&#125;".format(motto = 'spam', pork = 'ham')   # 基于Key的调用<br>    "&#123;motto&#125; and &#123;0&#125;".format('ham', motto = 'spam')             # 混合调用<br>    s3 = f"&#123;name&#125; 性格： &#123;xingge&#125;, 爱好: &#123;aihao&#125;" # f format<br>    # 添加键 属性 偏移量 (import sys)<br>    "my &#123;1[spam]&#125; runs &#123;0.platform&#125;".format(sys, &#123;'spam':'laptop'&#125;)                 # 基于位置的键和属性<br>    "&#123;config[spam]&#125; &#123;sys.platform&#125;".format(sys = sys, config = &#123;'spam':'laptop'&#125;)   # 基于Key的键和属性<br>    "first = &#123;0[0]&#125;, second = &#123;0[1]&#125;".format(['A', 'B', 'C'])                       # 基于位置的偏移量<br>    # 具体格式化<br>    "&#123;0:e&#125;, &#123;1:.3e&#125;, &#123;2:g&#125;".format(3.14159, 3.14159, 3.14159)   # 输出'3.141590e+00, 3.142e+00, 3.14159'<br>    "&#123;fieldname:format_spec&#125;".format(......)<br>    # 说明:<br>    """<br>        fieldname是指定参数的一个数字或关键字, 后边可跟可选的".name"或"[index]"成分引用<br>        format_spec ::=  [[fill]align][sign][#][0][width][,][.precision][type]<br>        fill        ::=  &lt;any character&gt;              #填充字符<br>        align       ::=  "&lt;" | "&gt;" | "=" | "^"        #对齐方式<br>        sign        ::=  "+" | "-" | " "              #符号说明<br>        width       ::=  integer                      #字符串宽度<br>        precision   ::=  integer                      #浮点数精度<br>        type        ::=  "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"<br>    """<br>    # 例子:<br>        '=&#123;0:10&#125; = &#123;1:10&#125;'.format('spam', 123.456)    # 输出'=spam       =    123.456'<br>        '=&#123;0:&gt;10&#125;='.format('test')                    # 输出'=      test='<br>        '=&#123;0:&lt;10&#125;='.format('test')                    # 输出'=test      ='<br>        '=&#123;0:^10&#125;='.format('test')                    # 输出'=   test   ='<br>        '&#123;0:X&#125;, &#123;1:o&#125;, &#123;2:b&#125;'.format(255, 255, 255)   # 输出'FF, 377, 11111111'<br>        'My name is &#123;0:&#123;1&#125;&#125;.'.format('Fred', 8)       # 输出'My name is Fred    .'  动态指定参数<br><br>#-- 常用列表常量和操作<br>    L = [[1, 2], 'string', &#123;&#125;]                        # 嵌套列表<br>    L = list('spam')                                  # 列表初始化<br>    L = list(range(0, 4))                             # 列表初始化<br>    list(map(ord, 'spam'))                            # 列表解析<br>    len(L)                                            # 求列表长度<br>    L.count(value)                                    # 求列表中某个值的个数<br>    L.append(obj)                                     # 向列表的尾部添加数据，比如append(2)，添加元素2<br>    L.insert(index, obj)                              # 向列表的指定index位置添加数据，index及其之后的数据后移<br>    L.extend(interable)                               # 通过添加iterable中的元素来扩展列表，比如extend([2])，添加元素2，注意和append的区别<br>    L.index(value, [start, [stop]])                   # 返回列表中值value的第一个索引<br>    L.pop([index])                                    # 删除并返回index处的元素，默认为删除并返回最后一个元素<br>    L.remove(value)                                   # 删除列表中的value值，只删除第一次出现的value的值<br>    L.reverse()                                       # 反转列表<br>    L.sort(cmp=None, key=None, reverse=False)         # 排序列表<br>    a = [1, 2, 3], b = a[10:]                         # 注意，这里不会引发IndexError异常，只会返回一个空的列表[]<br>    a = [], a += [1]                                  # 这里实在原有列表的基础上进行操作，即列表的id没有改变<br>    a = [], a = a + [1]                               # 这里最后的a要构建一个新的列表，即a的id发生了变化<br>    del a[::2]                                        # 去除偶数项(偶数索引的)，a = [1, 3, 5, 7]<br><br>    L = [x**2 for x in range(5)]                      # 列表解析<br>#-- 用切片来删除序列的某一段<br>    a = [1, 2, 3, 4, 5, 6, 7]<br>    a[1:4] = []                                       # a = [1, 5, 6, 7]<br>    a = [0, 1, 2, 3, 4, 5, 6, 7]<br>    del a[::2]                                        # 去除偶数项(偶数索引的)，a = [1, 3, 5, 7]<br>    <br>#-- 常用字典常量和操作<br>    D = &#123;&#125;<br>    D = &#123;'spam':2, 'tol':&#123;'ham':1&#125;&#125;                   # 嵌套字典<br>    D = dict.fromkeys(['s', 'd'], 8)                  # &#123;'s': 8, 'd': 8&#125;<br>    D = dict(name = 'tom', age = 12)                  # &#123;'age': 12, 'name': 'tom'&#125;<br>    D = dict([('name', 'tom'), ('age', 12)])          # &#123;'age': 12, 'name': 'tom'&#125;<br>    D = dict(zip(['name', 'age'], ['tom', 12]))       # &#123;'age': 12, 'name': 'tom'&#125;<br>    D.keys(); D.values(); D.items()                   # 字典键、值以及键值对<br>    D.get(key, default)                               # get函数<br>    D.update(D_other)                                 # 合并字典，如果存在相同的键值，D_other的数据会覆盖掉D的数据<br>    D.pop(key, [D])                                   # 删除字典中键值为key的项，返回键值为key的值，如果不存在，返回默认值D，否则异常<br>    D.popitem()                                       # pop字典中随机的一项（一个键值对）<br>    D.setdefault(k[, d])                              # 设置D中某一项的默认值。如果k存在，则返回D[k]，否则设置D[k]=d，同时返回D[k]。<br>    del D                                             # 删除字典<br>    del D['key']                                      # 删除字典的某一项<br>    if key in D:   if key not in D:                   # 测试字典键是否存在<br>    # 字典注意事项：（1）对新索引赋值会添加一项（2）字典键不一定非得是字符串，也可以为任何的不可变对象<br>    # 不可变对象：调用对象自身的任意方法，也不会改变该对象自身的内容，这些方法会创建新的对象并返回。<br>    # 字符串、整数、tuple都是不可变对象，dict、set、list都是可变对象<br>    D[(1,2,3)] = 2                                    # tuple作为字典的key<br><br>#-- 字典解析<br>    D = &#123;k:8 for k in ['s', 'd']&#125;                     # &#123;'s': 8, 'd': 8&#125;<br>    D = &#123;k:v for (k, v) in zip(['name', 'age'], ['tom', 12])&#125;       # &#123;'age': 12, 'name': tom&#125;<br>    <br>#-- 字典的特殊方法__missing__：当查找找不到key时，会执行该方法<br>    class Dict(dict):<br>        def __missing__(self, key):<br>            self[key] = []<br>            return self[key]<br>    dct = dict()<br>    dct["foo"].append(1)    # 这有点类似于collections.defalutdict<br>    dct["foo"]              # [1]<br>    <br>#-- 元组和列表的唯一区别在于元组是不可变对象，列表是可变对象<br>    a = [1, 2, 3]           # a[1] = 0, OK<br>    a = (1, 2, 3)           # a[1] = 0, Error<br>    a = ([1, 2])            # a[0][1] = 0, OK<br>    a = [(1, 2)]            # a[0][1] = 0, Error<br>    <br>#-- 元组的特殊语法: 逗号和圆括号<br>    D = (12)                # 此时D为一个整数 即D = 12<br>    D = (12, )              # 此时D为一个元组 即D = (12, )<br>    <br>#-- 文件基本操作<br>    output = open(r'C:\spam', 'w')          # 打开输出文件，用于写<br>    input = open('data', 'r')               # 打开输入文件，用于读。打开的方式可以为'w', 'r', 'a', 'wb', 'rb', 'ab'等<br>    fp.read([size])                         # size为读取的长度，以byte为单位<br>    fp.readline([size])                     # 读一行，如果定义了size，有可能返回的只是一行的一部分<br>    fp.readlines([size])                    # 把文件每一行作为一个list的一个成员，并返回这个list。其实它的内部是通过循环调用readline()来实现的。如果提供size参数，size是表示读取内容的总长。<br>    fp.readable()                           # 是否可读<br>    fp.write(str)                           # 把str写到文件中，write()并不会在str后加上一个换行符<br>    fp.writelines(seq)                      # 把seq的内容全部写到文件中(多行一次性写入)<br>    fp.writeable()                          # 是否可写<br>    fp.close()                              # 关闭文件。<br>    fp.flush()                              # 把缓冲区的内容写入硬盘<br>    fp.fileno()                             # 返回一个长整型的”文件标签“<br>    fp.isatty()                             # 文件是否是一个终端设备文件（unix系统中的）<br>    fp.tell()                               # 返回文件操作标记的当前位置，以文件的开头为原点<br>    fp.next()                               # 返回下一行，并将文件操作标记位移到下一行。把一个file用于for … in file这样的语句时，就是调用next()函数来实现遍历的。<br>    fp.seek(offset[,whence])                # 将文件打开操作标记移到offset的位置。whence为0表示从头开始计算，1表示以当前位置为原点计算。2表示以文件末尾为原点进行计算。<br>    fp.seekable()                           # 是否可以seek<br>    fp.truncate([size])                     # 把文件裁成规定的大小，默认的是裁到当前文件操作标记的位置。<br>    for line in open('data'): <br>        print(line)                         # 使用for语句，比较适用于打开比较大的文件<br>    with open('data') as file:<br>        print(file.readline())              # 使用with语句，可以保证文件关闭<br>    with open('data') as file:<br>        lines = file.readlines()            # 一次读入文件所有行，并关闭文件<br>    open('f.txt', encoding = 'latin-1')     # Python3.x Unicode文本文件<br>    open('f.bin', 'rb')                     # Python3.x 二进制bytes文件<br>    # 文件对象还有相应的属性：buffer closed encoding errors line_buffering name newlines等<br>    <br>#-- 其他<br>    # Python中的真假值含义：1. 数字如果非零，则为真，0为假。 2. 其他对象如果非空，则为真<br>    # 通常意义下的类型分类：1. 数字、序列、映射。 2. 可变类型和不可变类型<br><br><br>"""语法和语句----语法和语句----语法和语句----语法和语句----语法和语句----语法和语句----语法和语句----语法和语句----语法和语句----语法和语句----语法和语句"""<br>#-- 引用与拷贝<br>    #没有限制条件的分片表达式 (l[:]) 能够复制序列.<br>    #字典copy方法(x.copy) 能够复制字典<br>    #有些内置函数 list 能够生成拷贝(list(l))<br>    #copy能够完整拷贝<br>    <br>    #浅拷贝<br>    L = [1,2,3]<br>    D = &#123;"a":1,"b":2&#125;<br>    A = L[:]                                #浅拷贝,无法复制嵌套结构<br>    B = D.copy()                            #同上<br><br>    #完全拷贝<br>    #标准的copy模块import copy 语句<br>    #x = copy.deepcoy(y)<br>    #<br># --  比较 相等性 和真值<br>    #" == " 操作符测试值得相等性.<br>    #" is " 表达式测试对象一致性 <br><br>#-- 赋值语句的形式<br>    spam = 'spam'                          # 基本形式<br>    spam, ham = 'spam', 'ham'              # 元组赋值形式<br>    [spam, ham] = ['s', 'h']               # 列表赋值形式<br>    a, b, c, d = 'abcd'                    # 序列赋值形式<br>    a, *b, c = 'spam'                      # 序列解包形式（Python3.x中才有）<br>    spam = ham = 'no'                      # 多目标赋值运算，涉及到共享引用<br>    spam += 42                             # 增强赋值，涉及到共享引用<br><br>#-- 序列赋值 序列解包<br>    [a, b, c] = (1, 2, 3)                  # a = 1, b = 2, c = 3<br>    a, b, c, d = "spam"                    # a = 's', b = 'p', c = 'a', d = 'm'<br>    a, b, c = range(3)                     # a = 0, b = 1, c = 2<br>    a, *b = [1, 2, 3, 4]                   # a = 1, b = [2, 3, 4]<br>    *a, b = [1, 2, 3, 4]                   # a = [1, 2, 3], b = 4<br>    a, *b, c = [1, 2, 3, 4]                # a = 1, b = [2, 3], c = 4<br>    # 带有*时 会优先匹配*之外的变量 如<br>    a, *b, c = [1, 2]                      # a = 1, c = 2, b = []<br><br>#-- print函数原型<br>    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)<br>    # 流的重定向<br>    print('hello world')                   # 等于sys.stdout.write('hello world')<br>    temp = sys.stdout                      # 原有流的保存<br>    sys.stdout = open('log.log', 'a')      # 流的重定向<br>    print('hello world')                   # 写入到文件log.log<br>    sys.stdout.close()<br>    sys.stdout = temp                      # 原有流的复原<br>    <br>#-- Python中and或or总是返回对象(左边的对象或右边的对象) 且具有短路求值的特性<br>    #  a为0返回b ,a非零返回a<br>    1 or 2 or 3                            # 返回 1<br>    #  a为0返回a,a非零返回b<br>    1 and 2 and 3                          # 返回 3<br><br>#-- if/else三元表达符（if语句在行内）<br>    A = 1 if X else 2<br>    A = 1 if X else (2 if Y else 3)<br>    # 也可以使用and-or语句（一条语句实现多个if-else）<br>    a = 6<br>    result = (a &gt; 20 and "big than 20" or a &gt; 10 and "big than 10" or a &gt; 5 and "big than 5")    # 返回"big than 5"<br><br>#-- Python的while语句或者for语句可以带else语句 当然也可以带continue/break/pass语句<br>    while a &gt; 1:<br>        anything<br>    else:<br>        anything<br>    # else语句会在循环结束后执行，除非在循环中执行了break，同样的还有for语句<br>    for i in range(5):<br>        anything<br>    else:<br>        anything<br><br>#-- for循环的元组赋值<br>    for (a, b) in [(1, 2), (3, 4)]:                   # 最简单的赋值<br>    for ((a, b), c) in [((1, 2), 3), ((4, 5), 6)]:    # 自动解包赋值<br>    for ((a, b), c) in [((1, 2), 3), ("XY", 6)]:      # 自动解包 a = X, b = Y, c = 6<br>    for (a, *b) in [(1, 2, 3), (4, 5, 6)]:            # 自动解包赋值<br><br>#-- 列表解析语法<br>    M = [[1,2,3], [4,5,6], [7,8,9]]<br>    res = [sum(row) for row in M]                     # G = [6, 15, 24] 一般的列表解析 生成一个列表<br>    res = [c * 2 for c in 'spam']                     # ['ss', 'pp', 'aa', 'mm']<br>    res = [a * b for a in [1, 2] for b in [4, 5]]     # 多解析过程 返回[4, 5, 8, 10]<br>    res = [a for a in [1, 2, 3] if a &lt; 2]             # 带判断条件的解析过程<br>    res = [a if a &gt; 0 else 0 for a in [-1, 0, 1]]     # 带判断条件的高级解析过程<br>    # 两个列表同时解析：使用zip函数<br>    for teama, teamb in zip(["Packers", "49ers"], ["Ravens", "Patriots"]):<br>        print(teama + " vs. " + teamb)<br>    # 带索引的列表解析：使用enumerate函数<br>    for index, team in enumerate(["Packers", "49ers", "Ravens", "Patriots"]):<br>        print(index, team)                            # 输出0, Packers \n 1, 49ers \n ......<br>    <br>#-- 生成器表达式<br>    G = (sum(row) for row in M)                       # 使用小括号可以创建所需结果的生成器generator object<br>    next(G), next(G), next(G)                         # 输出(6, 15, 24)<br>    G = &#123;sum(row) for row in M&#125;                       # G = &#123;6, 15, 24&#125; 解析语法还可以生成集合和字典<br>    G = &#123;i:sum(M[i]) for i in range(3)&#125;               # G = &#123;0: 6, 1: 15, 2: 24&#125;<br><br>#-- 文档字符串:出现在Module的开端以及其中函数或类的开端 使用三重引号字符串<br>    """<br>    module document<br>    """<br>    def func():<br>        """<br>        function document<br>        """<br>        print()<br>    class Employee(object):<br>        """<br>        class document<br>        """<br>        print()<br>    print(func.__doc__)                # 输出函数文档字符串<br>    print(Employee.__doc__)            # 输出类的文档字符串<br>    <br>#-- 命名惯例:<br>    """<br>    以单一下划线开头的变量名(_X)不会被from module import*等语句导入<br>    前后有两个下划线的变量名(__X__)是系统定义的变量名，对解释器有特殊意义<br>    以两个下划线开头但不以下划线结尾的变量名(__X)是类的本地(私有)变量<br>    """<br><br>#-- 列表解析 in成员关系测试 map sorted zip enumerate内置函数等都使用了迭代协议<br>    'first line' in open('test.txt')   # in测试 返回True或False<br>    list(map(str.upper, open('t')))    # map内置函数<br>    sorted(iter([2, 5, 8, 3, 1]))      # sorted内置函数<br>    list(zip([1, 2], [3, 4]))          # zip内置函数 [(1, 3), (2, 4)]<br>    #lst = [el for i in names for el in i if el.count("e") &gt;= 2 ]<br>#print(lst)<br><br>#-- del语句: 手动删除某个变量<br>    del X<br><br>#-- 获取列表的子表的方法:<br>    x = [1,2,3,4,5,6]<br>    x[:3]                              # 前3个[1,2,3]<br>    x[1:5]                             # 中间4个[2,3,4,5]<br>    x[-3:]                             # 最后3个[4,5,6]<br>    x[::2]                             # 奇数项[1,3,5]<br>    x[1::2]                            # 偶数项[2,4,6]<br>    <br>#-- 手动迭代：iter和next<br>    L = [1, 2]<br>    I = iter(L)                        # I为L的迭代器<br>    I.next()                           # 返回1<br>    I.next()                           # 返回2<br>    I.next()                           # Error:StopIteration<br>    <br>#-- Python中的可迭代对象<br>    """<br>    1.range迭代器<br>    2.map、zip和filter迭代器<br>    3.字典视图迭代器：D.keys()), D.items()等<br>    4.文件类型<br>    """<br><br><br>"""函数语法规则----函数语法规则----函数语法规则----函数语法规则----函数语法规则----函数语法规则----函数语法规则----函数语法规则----函数语法规则----函数语法规则"""<br><br>#-- 函数相关的语句和表达式<br>    myfunc('spam')                     # 函数调用<br>    def myfunc():                      # 函数定义<br>    return None                        # 函数返回值<br>    global a                           # 全局变量<br>    nonlocal x                         # 在函数或其他作用域中使用外层（非全局）变量<br>    yield x                            # 生成器函数返回<br>    lambda                             # 匿名函数<br>    <br>#-- Python函数变量名解析:LEGB原则，即:<br>    <br>    local(functin) --&gt; encloseing function locals --&gt; global(module) --&gt; build-in(python)<br>    #当前作用域局部变量-&gt;外层作用域变量-&gt;当前模块中的全局变量-&gt;python内置变量 。<br>    说明:以下边的函数maker为例 则相对于action而言 X为Local N为Encloseing<br>    global #  在局部引入全局变量<br>    nonlocal # 在局部, 引入离他最近的那一层的变量<br>    <br><br>#-- 嵌套函数举例:工厂函数<br>    def maker(N):<br>        def action(X):<br>            return X ** N<br>        return action<br>    f = maker(2)                       # pass 2 to N<br>    f(3)                               # 9, pass 3 to X<br><br>#-- 嵌套函数举例:lambda实例<br>    def maker(N):<br>        action = (lambda X: X**N)<br>        return action<br>    f = maker(2)                       # pass 2 to N<br>    f(3)                               # 9, pass 3 to X<br><br>#-- nonlocal和global语句的区别<br>    # nonlocal应用于一个嵌套的函数的作用域中的一个名称 例如:<br>    start = 100<br>    def tester(start):<br>        def nested(label):<br>            nonlocal start             # 指定start为tester函数内的local变量 而不是global变量start<br>            print(label, start)<br>            start += 3<br>        return nested<br>    # global为全局的变量 即def之外的变量<br>    def tester(start):<br>        def nested(label):<br>            global start               # 指定start为global变量start<br>            print(label, start)<br>            start += 3<br>        return nested    <br>    <br>#-- 函数参数，不可变参数通过“值”传递，可变参数通过“引用”传递<br>    def f(a, b, c): print(a, b, c)<br>    f(1, 2, 3)                         # 参数位置匹配<br>    f(1, c = 3, b = 2)                 # 参数关键字匹配<br>    def f(a, b=1, c=2): print(a, b, c)<br>    f(1)                               # 默认参数匹配<br>    f(1, 2)                            # 默认参数匹配<br>    f(a = 1, c = 3)                    # 关键字参数和默认参数的混合<br>    # Keyword-Only参数:出现在*args之后 必须用关键字进行匹配<br>    def keyOnly(a, *b, c): print('')   # c就为keyword-only匹配 必须使用关键字c = value匹配<br>    def keyOnly(a, *, b, c): ......    # b c为keyword-only匹配 必须使用关键字匹配<br>    def keyOnly(a, *, b = 1): ......   # b有默认值 或者省略 或者使用关键字参数b = value<br><br>#-- 可变参数匹配: * 和 **<br>    def f(*args): print(args)          # 在元组中收集不匹配的位置参数<br>    f(1, 2, 3)                         # 输出(1, 2, 3)<br>    def f(**args): print(args)         # 在字典中收集不匹配的关键字参数<br>    f(a = 1, b = 2)                    # 输出&#123;'a':1, 'b':2&#125;<br>    def f(a, *b, **c): print(a, b, c)  # 两者混合使用<br>    f(1, 2, 3, x=4, y=5)               # 输出1, (2, 3), &#123;'x':4, 'y':5&#125;<br>    <br>#-- 函数调用时的参数解包: * 和 ** 分别解包元组和字典<br>    func(1, *(2, 3))  &lt;==&gt;  func(1, 2, 3)<br>    func(1, **&#123;'c':3, 'b':2&#125;)  &lt;==&gt;  func(1, b = 2, c = 3)<br>    func(1, *(2, 3), **&#123;'c':3, 'b':2&#125;)  &lt;==&gt;  func(1, 2, 3, b = 2, c = 3)<br>    <br>#-- 函数属性:(自己定义的)函数可以添加属性<br>    def func():.....<br>    func.count = 1                     # 自定义函数添加属性<br>    print.count = 1                    # Error 内置函数不可以添加属性<br>    <br>#-- 函数注解: 编写在def头部行 主要用于说明参数范围、参数类型、返回值类型等<br>    def func(a:'spam', b:(1, 10), c:float) -&gt; int :<br>        print(a, b, c)<br>    func.__annotations__               # &#123;'c':&lt;class 'float'&gt;, 'b':(1, 10), 'a':'spam', 'return':&lt;class 'int'&gt;&#125;<br>    # 编写注解的同时 还是可以使用函数默认值 并且注解的位置位于=号的前边<br>    def func(a:'spam'='a', b:(1, 10)=2, c:float=3) -&gt; int :<br>        print(a, b, c)<br><br>#-- 匿名函数:lambda<br>    f = lambda x, y, z : x + y + z     # 普通匿名函数，使用方法f(1, 2, 3)<br>    f = lambda x = 1, y = 1: x + y     # 带默认参数的lambda函数<br>    def action(x):                     # 嵌套lambda函数<br>        return (lambda y : x + y)<br>    f = lambda: a if xxx() else b      # 无参数的lambda函数，使用方法f()<br><br>#-- lambda函数与map filter reduce函数的结合<br>    list(map((lambda x: x + 1), [1, 2, 3]))              # [2, 3, 4]<br>    list(filter((lambda x: x &gt; 0), range(-4, 5)))        # [1, 2, 3, 4]<br>    functools.reduce((lambda x, y: x + y), [1, 2, 3])    # 6<br>    functools.reduce((lambda x, y: x * y), [2, 3, 4])    # 24<br>    <br>#-- 生成器函数:yield VS return<br>    def gensquare(N):<br>        for i in range(N):<br>            yield i** 2                # 状态挂起 可以恢复到此时的状态<br>    for i in gensquare(5):             # 使用方法<br>        print(i, end = ' ')            # [0, 1, 4, 9, 16]<br>    x = gensquare(2)                   # x是一个生成对象<br>    next(x)                            # 等同于x.__next__() 返回0<br>    next(x)                            # 等同于x.__next__() 返回1<br>    next(x)                            # 等同于x.__next__() 抛出异常StopIteration<br>    <br>#-- 生成器表达式:小括号进行列表解析<br>    G = (x ** 2 for x in range(3))     # 使用小括号可以创建所需结果的生成器generator object<br>    next(G), next(G), next(G)          # 和上述中的生成器函数的返回值一致<br>    #（1）生成器(生成器函数/生成器表达式)是单个迭代对象<br>    G = (x ** 2 for x in range(4))<br>    I1 = iter(G)                       # 这里实际上iter(G) = G<br>    next(I1)                           # 输出0<br>    next(G)                            # 输出1<br>    next(I1)                           # 输出4<br>    #（2）生成器不保留迭代后的结果<br>    gen = (i for i in range(4))<br>    2 in gen                           # 返回True<br>    3 in gen                           # 返回True<br>    1 in gen                           # 返回False，其实检测2的时候，1已经就不在生成器中了，即1已经被迭代过了，同理2、3也不在了<br><br>#-- 本地变量是静态检测的<br>    X = 22                             # 全局变量X的声明和定义<br>    def test():<br>        print(X)                       # 如果没有下一语句 则该句合法 打印全局变量X<br>        X = 88                         # 这一语句使得上一语句非法 因为它使得X变成了本地变量 上一句变成了打印一个未定义的本地变量(局部变量)<br>        if False:                      # 即使这样的语句 也会把print语句视为非法语句 因为:<br>            X = 88                     # Python会无视if语句而仍然声明了局部变量X<br>    def test():                        # 改进<br>        global X                       # 声明变量X为全局变量<br>        print(X)                       # 打印全局变量X<br>        X = 88                         # 改变全局变量X<br>        <br>#-- 函数的默认值是在函数定义的时候实例化的 而不是在调用的时候 例子:<br>    def foo(numbers=[]):               # 这里的[]是可变的<br>        numbers.append(9)    <br>        print(numbers)<br>    foo()                              # first time, like before, [9]<br>    foo()                              # second time, not like before, [9, 9]<br>    foo()                              # third time, not like before too, [9, 9, 9]<br>    # 改进:<br>    def foo(numbers=None):<br>        if numbers is None: numbers = []<br>        numbers.append(9)<br>        print(numbers)<br>    # 另外一个例子 参数的默认值为不可变的:<br>    def foo(count=0):                  # 这里的0是数字, 是不可变的<br>        count += 1<br>        print(count)<br>    foo()                              # 输出1<br>    foo()                              # 还是输出1<br>    foo(3)                             # 输出4<br>    foo()                              # 还是输出1<br>    <br><br>"""函数例子----函数例子----函数例子----函数例子----函数例子----函数例子----函数例子----函数例子----函数例子----函数例子----函数例子----函数例子----函数例子"""<br><br>    """数学运算类"""<br>    abs(x)                              # 求绝对值，参数可以是整型，也可以是复数，若参数是复数，则返回复数的模<br>    complex([real[, imag]])             # 创建一个复数<br>    divmod(a, b)                        # 分别取商和余数，注意：整型、浮点型都可以<br>    float([x])                          # 将一个字符串或数转换为浮点数。如果无参数将返回0.0<br>    int([x[, base]])                    # 将一个字符串或浮点数转换为int类型，base表示进制<br>    long([x[, base]])                   # 将一个字符串或浮点数转换为long类型<br>    pow(x, y)                           # 返回x的y次幂<br>    range([start], stop[, step])        # 产生一个序列，默认从0开始<br>    round(x[, n])                       # 四舍五入<br>    sum(iterable[, start])              # 对集合求和<br>    oct(x)                              # 将一个数字转化为8进制字符串<br>    hex(x)                              # 将一个数字转换为16进制字符串<br>    chr(i)                              # 返回给定int类型对应的ASCII字符<br>    unichr(i)                           # 返回给定int类型的unicode<br>    ord(c)                              # 返回ASCII字符对应的整数<br>    bin(x)                              # 将整数x转换为二进制字符串<br>    bool([x])                           # 将x转换为Boolean类型<br>    <br>    """集合类操作"""<br>    basestring()                        # str和unicode的超类，不能直接调用，可以用作isinstance判断<br>    format(value [, format_spec])       # 格式化输出字符串，格式化的参数顺序从0开始，如“I am &#123;0&#125;,I like &#123;1&#125;”<br>    enumerate(sequence[, start=0])      # 返回一个可枚举的对象，注意它有第二个参数<br>    iter(obj[, sentinel])               # 生成一个对象的迭代器，第二个参数表示分隔符<br>    max(iterable[, args...][key])       # 返回集合中的最大值<br>    min(iterable[, args...][key])       # 返回集合中的最小值<br>    dict([arg])                         # 创建数据字典<br>    list([iterable])                    # 将一个集合类转换为另外一个集合类<br>    set()                               # set对象实例化<br>    frozenset([iterable])               # 产生一个不可变的set<br>    tuple([iterable])                   # 生成一个tuple类型<br>    str([object])                       # 转换为string类型<br>    sorted(iterable[, cmp[, key[, reverse]]])             # 集合排序<br>        L = [('b',2),('a',1),('c',3),('d',4)]<br>        sorted(L, key=lambda x: x[1], reverse=True)       # 使用Key参数和reverse参数<br>        sorted(L, key=lambda x: (x[0], x[1]))             # 使用key参数进行多条件排序，即如果x[0]相同，则比较x[1]<br><br>    """逻辑判断"""<br>    all(iterable)                       # 集合中的元素都为真的时候为真，特别的，若为空串返回为True<br>    any(iterable)                       # 集合中的元素有一个为真的时候为真，特别的，若为空串返回为False<br>    cmp(x, y)                           # 如果x &lt; y ,返回负数；x == y, 返回0；x &gt; y,返回正数<br><br>    """IO操作"""<br>    file(filename [, mode [, bufsize]]) # file类型的构造函数。<br>    input([prompt])                     # 获取用户输入，推荐使用raw_input，因为该函数将不会捕获用户的错误输入，意思是自行判断类型<br>    # 在 Built-in Functions 里有一句话是这样写的：Consider using the raw_input() function for general input from users.<br>    raw_input([prompt])                 # 设置输入，输入都是作为字符串处理<br>    open(name[, mode[, buffering]])     # 打开文件，与file有什么不同？推荐使用open<br>    <br>    """其他"""<br>    callable(object)                    # 检查对象object是否可调用<br>    classmethod(func)                   # 用来说明这个func是个类方法<br>    staticmethod(func)                  # 用来说明这个func为静态方法<br>    dir([object])                       # 不带参数时，返回当前范围内的变量、方法和定义的类型列表；带参数时，返回参数的属性、方法列表。<br>    help(obj)                           # 返回obj的帮助信息<br>    eval(expression)                    # 计算表达式expression的值，并返回<br>    exec(str)                           # 将str作为Python语句执行<br>    execfile(filename)                  # 用法类似exec()，不同的是execfile的参数filename为文件名，而exec的参数为字符串。<br>    filter(function, iterable)          # 构造一个序列，等价于[item for item in iterable if function(item)]，function返回值为True或False的函数<br>        list(filter(bool, range(-3, 4)))# 返回[-3, -2, -1, 1, 2, 3], 没有0<br>    <br>    #反射<br>    hasattr(object, name)               # 判断对象object是否包含名为name的特性\成员<br>    getattr(object, name [, defalut])   # 获取一个类的属性<br>    setattr(object, name, value)        # 设置属性值value . 注意. 这里的value可以是值, 也可以是函数或者方法<br>    delattr(object, name)               # 删除object对象名为name的属性<br>    #反射<br>    #<br>    globals()                           # 返回一个描述当前全局符号表的字典<br>    hash(object)                        # 如果对象object为哈希表类型，返回对象object的哈希值<br>    id(object)                          # 返回对象的唯一标识，一串数字<br>    isinstance(object, classinfo)       # 判断object是否是class的实例<br>        isinstance(1, int)              # 判断是不是int类型<br>        isinstance(1, (int, float))     # isinstance的第二个参数接受一个元组类型<br>    issubclass(class, classinfo)        # 判断class是否为classinfo的子类<br>    locals()                            # 返回当前的变量列表<br>    map(function, iterable, ...)        # 遍历每个元素，执行function操作<br>        list(map(abs, range(-3, 4)))    # 返回[3, 2, 1, 0, 1, 2, 3]<br>    next(iterator[, default])           # 类似于iterator.next()<br>    property([fget[, fset[, fdel[, doc]]]])           # 属性访问的包装类，设置后可以通过c.x=value等来访问setter和getter<br>    reduce(function, iterable[, initializer])         # 合并操作，从第一个开始是前两个参数，然后是前两个的结果与第三个合并进行处理，以此类推<br>        def add(x,y):return x + y <br>        reduce(add, range(1, 11))                     # 返回55 (注:1+2+3+4+5+6+7+8+9+10 = 55)<br>        reduce(add, range(1, 11), 20)                 # 返回75<br>    reload(module)                      # 重新加载模块<br>    repr(object)                        # 将一个对象变幻为可打印的格式<br>    slice(start, stop[, step])          # 产生分片对象<br>    type(object)                        # 返回该object的类型<br>    vars([object])                      # 返回对象的变量名、变量值的字典<br>        a = Class();                    # Class为一个空类<br>        a.name = 'qi', a.age = 9<br>        vars(a)                         # &#123;'name':'qi', 'age':9&#125;<br>    zip([iterable, ...])                # 返回对应数组<br>        list(zip([1, 2, 3], [4, 5, 6])) # [(1, 4), (2, 5), (3, 6)]<br>        a = [1, 2, 3],  b = ["a", "b", "c"]<br>        z = zip(a, b)                   # 压缩：[(1, "a"), (2, "b"), (3, "c")]<br>        zip(*z)                         # 解压缩：[(1, 2, 3), ("a", "b", "c")]<br>    unicode(string, encoding, errors)   # 将字符串string转化为unicode形式，string为encoded string。<br><br>    <br>"""模块Moudle----模块Moudle----模块Moudle----模块Moudle----模块Moudle----模块Moudle----模块Moudle----模块Moudle----模块Moudle----模块Moudle----模块Moudle"""<br><br>#-- Python模块搜索路径:<br>    """<br>    (1)程序的主目录    (2)PYTHONPATH目录 (3)标准链接库目录 (4)任何.pth文件的内容<br>    """<br>    <br>#-- 查看全部的模块搜索路径<br>    import sys<br>    sys.path<br>    sys.argv                            # 获得脚本的参数<br>    sys.builtin_module_names            # 查找内建模块<br>    sys.platform                        # 返回当前平台 出现如： "win32" "linux" "darwin"等<br>    sys.modules                         # 查找已导入的模块<br>    sys.modules.keys()<br>    sys.stdout                          # stdout 和 stderr 都是类文件对象，但是它们都是只写的。它们都没有 read 方法，只有 write 方法<br>    sys.stdout.write("hello")<br>    sys.stderr<br>    sys.stdin   <br><br>#-- 模块的使用代码<br>    import module1, module2             # 导入module1 使用module1.printer()<br>    from module1 import printer         # 导入module1中的printer变量 使用printer()<br>    from module1 import *               # 导入module1中的全部变量 使用不必添加module1前缀<br><br>#-- 重载模块reload: 这是一个内置函数 而不是一条语句<br>    from imp import reload<br>    reload(module)<br>    <br>#-- 模块的包导入:使用点号(.)而不是路径(dir1\dir2)进行导入<br>    import dir1.dir2.mod                # d导入包(目录)dir1中的包dir2中的mod模块 此时dir1必须在Python可搜索路径中<br>    from dir1.dir2.mod import *         # from语法的包导入<br><br>#-- __init__.py包文件:每个导入的包中都应该包含这么一个文件<br>    """<br>    该文件可以为空<br>    首次进行包导入时 该文件会自动执行<br>    高级功能:在该文件中使用__all__列表来定义包(目录)以from*的形式导入时 需要导入什么<br>    """<br>    <br>#-- 包相对导入:使用点号(.) 只能使用from语句<br>    from . import spam                  # 导入当前目录下的spam模块（Python2: 当前目录下的模块, 直接导入即可）<br>    from .spam import name              # 导入当前目录下的spam模块的name属性（Python2: 当前目录下的模块, 直接导入即可，不用加.）<br>    from .. import spam                 # 导入当前目录的父目录下的spam模块<br>    <br>#-- 包相对导入与普通导入的区别<br>    from string import *                # 这里导入的string模块为sys.path路径上的 而不是本目录下的string模块(如果存在也不是)<br>    from .string import *               # 这里导入的string模块为本目录下的(不存在则导入失败) 而不是sys.path路径上的<br>    <br>#-- 模块数据隐藏:最小化from*的破坏<br>    _X                                  # 变量名前加下划线可以防止from*导入时该变量名被复制出去<br>    __all__ = ['x', 'x1', 'x2']         # 使用__all__列表指定from*时复制出去的变量名(变量名在列表中为字符串形式)<br><br>#-- 可以使用__name__进行模块的单元测试:当模块为顶层执行文件时值为'__main__' 当模块被导入时为模块名<br>    if __name__ == '__main__':<br>        doSomething<br>    # 模块属性中还有其他属性，例如：<br>    __doc__                             # 模块的说明文档<br>    __file__                            # 模块文件的文件名，包括全路径<br>    __name__                            # 主文件或者被导入文件<br>    __package__                         # 模块所在的包<br>        <br>#-- import语句from语句的as扩展<br>    import modulename as name<br>    from modulename import attrname as name<br>    <br>#-- 得到模块属性的几种方法 假设为了得到name属性的值<br>    M.name<br>    M.__dict__['name']<br>    sys.modules['M'].name<br>    getattr(M, 'name')<br>    <br><br>"""类与面向对象----类与面向对象----类与面向对象----类与面向对象----类与面向对象----类与面向对象----类与面向对象----类与面向对象----类与面向对象----类与面向对象"""<br><br>#-- 最普通的类<br>    class C1(C2, C3):<br>        spam = 42                       # 数据属性<br>        def __init__(self, name):       # 函数属性:构造函数<br>            self.name = name<br>        def __del__(self):              # 函数属性:析构函数<br>            print("goodbey ", self.name)    <br>    I1 = C1('bob')<br>    <br>#-- Python的类没有基于参数的函数重载<br>    class FirstClass(object):<br>        def test(self, string):<br>            print(string)<br>        def test(self):                 # 此时类中只有一个test函数 即后者test(self) 它覆盖掉前者带参数的test函数<br>            print("hello world")<br><br>#-- 子类扩展超类: 尽量调用超类的方法<br>    class Manager(Person):<br>        def giveRaise(self, percent, bonus = .10):<br>            self.pay = int(self.pay*(1 + percent + bonus))     # 不好的方式 复制粘贴超类代码<br>            Person.giveRaise(self, percent + bonus)            # 好的方式 尽量调用超类方法<br><br>#-- 类内省工具<br>    bob = Person('bob')<br>    bob.__class__                       # &lt;class 'Person'&gt;<br>    bob.__class__.__name__              # 'Person'<br>    bob.__dict__                        # &#123;'pay':0, 'name':'bob', 'job':'Manager'&#125;<br>    <br>#-- 返回1中 数据属性spam是属于类 而不是对象<br>    I1 = C1('bob'); I2 = C2('tom')      # 此时I1和I2的spam都为42 但是都是返回的C1的spam属性<br>    C1.spam = 24                        # 此时I1和I2的spam都为24<br>    I1.spam = 3                         # 此时I1新增自有属性spam 值为3 I2和C1的spam还都为24<br>    <br>#-- 类方法调用的两种方式<br>    instance.method(arg...)         #对象访问,方法<br>    class.method(instance, arg...)  #类名访问,函数<br>    <br>#-- 抽象超类的实现方法<br>    # (1)某个函数中调用未定义的函数 子类中定义该函数<br>        def delegate(self):<br>            self.action()               # 本类中不定义action函数 所以使用delegate函数时就会出错<br>    # (2)定义action函数 但是返回异常<br>        def action(self):<br>            raise NotImplementedError("action must be defined")<br>    # (3)上述的两种方法还都可以定义实例对象 实际上可以利用@装饰器语法生成不能定义的抽象超类<br>        from abc import ABCMeta, abstractmethod<br>        class Super(metaclass = ABCMeta):<br>            @abstractmethod<br>            def action(self): pass<br>        x = Super()                     # 返回 TypeError: Can't instantiate abstract class Super with abstract methods action<br>    <br>#-- # OOP和继承: "is-a"的关系<br>    class A(B):<br>        pass<br>    a = A()<br>    isinstance(a, B)                    # 返回True, A是B的子类 a也是B的一种<br>    # OOP和组合: "has-a"的关系<br>    pass<br>    # OOP和委托: "包装"对象 在Python中委托通常是以"__getattr__"钩子方法实现的, 这个方法会拦截对不存在属性的读取<br>    # 包装类(或者称为代理类)可以使用__getattr__把任意读取转发给被包装的对象<br>    class wrapper(object):<br>        def __init__(self, object):<br>            self.wrapped = object<br>        def __getattr(self, attrname):<br>            print('Trace: ', attrname)<br>            return getattr(self.wrapped, attrname)<br>    # 注:这里使用getattr(X, N)内置函数以变量名字符串N从包装对象X中取出属性 类似于X.__dict__[N]<br>    x = wrapper([1, 2, 3])<br>    x.append(4)                         # 返回 "Trace: append" [1, 2, 3, 4]<br>    x = wrapper(&#123;'a':1, 'b':2&#125;)<br>    list(x.keys())                      # 返回 "Trace: keys" ['a', 'b']<br><br>#-- 类的伪私有属性:使用__attr<br>    class C1(object):<br>        def __init__(self, name):<br>            self.__name = name          # 此时类的__name属性为伪私有属性 原理 它会自动变成self._C1__name = name<br>        def __str__(self):<br>            return 'self.name = %s' % self.__name<br>    I = C1('tom')<br>    print(I)                            # 返回 self.name = tom<br>    I.__name = 'jeey'                   # 这里无法访问 __name为伪私有属性<br>    I._C1__name = 'jeey'                # 这里可以修改成功 self.name = jeey<br>    <br>#-- 类方法是对象:无绑定类方法对象 / 绑定实例方法对象<br>    class Spam(object):<br>        def doit(self, message):<br>            print(message)<br>        def selfless(message)<br>            print(message)<br>    obj = Spam()<br>    x = obj.doit                        # 类的绑定方法对象 实例 + 函数<br>    x('hello world')<br>    x = Spam.doit                       # 类的无绑定方法对象 类名 + 函数<br>    x(obj, 'hello world')<br>    x = Spam.selfless                   # 类的无绑定方法函数 在3.0之前无效<br>    x('hello world')<br><br>#-- 获取对象信息: 属性和方法<br>    a = MyObject()<br>    dir(a)                              # 使用dir函数<br>    hasattr(a, 'x')                     # 测试是否有x属性或方法 即a.x是否已经存在<br>    setattr(a, 'y', 19)                 # 设置属性或方法 等同于a.y = 19<br>    getattr(a, 'z', 0)                  # 获取属性或方法 如果属性不存在 则返回默认值0<br>    #这里有个小技巧，setattr可以设置一个不能访问到的属性，即只能用getattr获取<br>    setattr(a, "can't touch", 100)      # 这里的属性名带有空格，不能直接访问<br>    getattr(a, "can't touch", 0)        # 但是可以用getattr获取<br><br>#-- 为类动态绑定属性或方法: MethodType方法<br>    # 一般创建了一个class的实例后, 可以给该实例绑定任何属性和方法, 这就是动态语言的灵活性<br>    class Student(object):<br>        pass<br>    s = Student()<br>    s.name = 'Michael'                  # 动态给实例绑定一个属性<br>    def set_age(self, age):             # 定义一个函数作为实例方法<br>        self.age = age<br>    from types import MethodType<br>    s.set_age = MethodType(set_age, s)  # 给实例绑定一个方法 类的其他实例不受此影响<br>    s.set_age(25)                       # 调用实例方法<br>    Student.set_age = MethodType(set_age, Student)    # 为类绑定一个方法 类的所有实例都拥有该方法<br><br>    <br>"""类的高级话题----类的高级话题----类的高级话题----类的高级话题----类的高级话题----类的高级话题----类的高级话题----类的高级话题----类的高级话题----类的高级话题"""<br>    <br>#-- 多重继承: "混合类", 搜索方式"从下到上 从左到右 广度优先"<br>    class A(B, C):<br>        pass<br><br>#-- 类的继承和子类的初始化<br>    # 1.子类定义了__init__方法时，若未显示调用基类__init__方法，python不会帮你调用。<br>    # 2.子类未定义__init__方法时，python会自动帮你调用首个基类的__init__方法，注意是首个。<br>    # 3.子类显示调用基类的初始化函数：<br>    class FooParent(object):<br>        def __init__(self, a):<br>            self.parent = 'I\'m the Parent.'<br>            print('Parent:a=' + str(a))<br>        def bar(self, message):<br>            print(message + ' from Parent')<br>    class FooChild(FooParent):<br>        def __init__(self, a):<br>            FooParent.__init__(self, a)<br>            print('Child:a=' + str(a))<br>        def bar(self, message):<br>            FooParent.bar(self, message)<br>            print(message + ' from Child')<br>    fooChild = FooChild(10)<br>    fooChild.bar('HelloWorld')<br>    <br>#-- #实例方法 / 静态方法 / 类方法<br>    class Methods(object):<br>        def imeth(self, x): print(self, x)      # 实例方法：传入的是实例和数据，操作的是实例的属性<br>        def smeth(x): print(x)                  # 静态方法：只传入数据 不传入实例，操作的是类的属性而不是实例的属性<br>        def cmeth(cls, x): print(cls, x)        # 类方法：传入的是类对象和数据<br>        smeth = staticmethod(smeth)             # 调用内置函数，也可以使用@staticmethod<br>        cmeth = classmethod(cmeth)              # 调用内置函数，也可以使用@classmethod<br>    obj = Methods()<br>    obj.imeth(1)                                # 实例方法调用 &lt;__main__.Methods object...&gt; 1<br>    Methods.imeth(obj, 2)                       # &lt;__main__.Methods object...&gt; 2<br>    Methods.smeth(3)                            # 静态方法调用 3<br>    obj.smeth(4)                                # 这里可以使用实例进行调用<br>    Methods.cmeth(5)                            # 类方法调用 &lt;class '__main__.Methods'&gt; 5<br>    obj.cmeth(6)                                # &lt;class '__main__.Methods'&gt; 6<br>    <br>#-- 函数装饰器:是它后边的函数的运行时的声明 由@符号以及后边紧跟的"元函数"(metafunction)组成<br>        @staticmethod<br>        def smeth(x): print(x)<br>    # 等同于:<br>        def smeth(x): print(x)<br>        smeth = staticmethod(smeth)<br>    # 同理<br>        @classmethod<br>        def cmeth(cls, x): print(x)<br>    # 等同于<br>        def cmeth(cls, x): print(x)<br>        cmeth = classmethod(cmeth)<br>    <br>#-- 类修饰器:是它后边的类的运行时的声明 由@符号以及后边紧跟的"元函数"(metafunction)组成<br>        def decorator(aClass):.....<br>        @decorator<br>        class C(object):....<br>    # 等同于:<br>        class C(object):....<br>        C = decorator(C)<br><br>#-- 限制class属性: __slots__属性<br>    class Student(object):<br>        __slots__ = ('name', 'age')             # 限制Student及其实例只能拥有name和age属性<br>    # __slots__属性只对当前类起作用, 对其子类不起作用<br>    # __slots__属性能够节省内存<br>    # __slots__属性可以为列表list，或者元组tuple<br>    <br>#-- 类属性高级话题: @property<br>    # 假设定义了一个类:C，该类必须继承自object类，有一私有变量_x<br>    class C(object):<br>        def __init__(self):<br>            self.__x = None<br>    # 第一种使用属性的方法<br>        def getx(self):<br>            return self.__x<br>        def setx(self, value):<br>            self.__x = value<br>        def delx(self):<br>            del self.__x<br>        x = property(getx, setx, delx, '')<br>    # property函数原型为property(fget=None,fset=None,fdel=None,doc=None)<br>    # 使用<br>    c = C()<br>    c.x = 100                         # 自动调用setx方法<br>    y = c.x                           # 自动调用getx方法<br>    del c.x                           # 自动调用delx方法<br>    # 第二种方法使用属性的方法<br>        @property<br>        def x(self):<br>            return self.__x<br>        @x.setter<br>        def x(self, value):<br>           self.__x = value<br>        @x.deleter<br>        def x(self):<br>           del self.__x<br>    # 使用<br>    c = C()<br>    c.x = 100                         # 自动调用setter方法<br>    y = c.x                           # 自动调用x方法<br>    del c.x                           # 自动调用deleter方法<br>    <br>#-- 定制类: 重写类的方法<br>    # (1)__str__方法、__repr__方法: 定制类的输出字符串<br>    # (2)__iter__方法、next方法: 定制类的可迭代性<br>    class Fib(object):<br>        def __init__(self):<br>            self.a, self.b = 0, 1     # 初始化两个计数器a，b<br>        def __iter__(self):<br>            return self               # 实例本身就是迭代对象，故返回自己<br>        def next(self):<br>            self.a, self.b = self.b, self.a + self.b<br>            if self.a &gt; 100000:       # 退出循环的条件<br>                raise StopIteration()<br>            return self.a             # 返回下一个值<br>    for n in Fib():<br>        print(n)                      # 使用<br>    # (3)__getitem__方法、__setitem__方法: 定制类的下标操作[] 或者切片操作slice<br>    class Indexer(object):<br>        def __init__(self):<br>            self.data = &#123;&#125;<br>        def __getitem__(self, n):             # 定义getitem方法<br>            print('getitem:', n)                <br>            return self.data[n]<br>        def __setitem__(self, key, value):    # 定义setitem方法<br>            print('setitem:key = &#123;0&#125;, value = &#123;1&#125;'.format(key, value))<br>            self.data[key] = value<br>    test = Indexer()<br>    test[0] = 1;   test[3] = '3'              # 调用setitem方法<br>    print(test[0])                            # 调用getitem方法<br>    # (4)__getattr__方法: 定制类的属性操作<br>    class Student(object):<br>        def __getattr__(self, attr):          # 定义当获取类的属性时的返回值<br>            if attr=='age':<br>                return 25                     # 当获取age属性时返回25<br>        raise AttributeError('object has no attribute: %s' % attr)<br>        # 注意: 只有当属性不存在时 才会调用该方法 且该方法默认返回None 需要在函数最后引发异常<br>    s = Student()<br>    s.age                                     # s中age属性不存在 故调用__getattr__方法 返回25<br>    # (5)__call__方法: 定制类的'可调用'性<br>    class Student(object):<br>        def __call__(self):                   # 也可以带参数<br>            print('Calling......')<br>    s = Student()<br>    s()                                       # s变成了可调用的 也可以带参数<br>    callable(s)                               # 测试s的可调用性 返回True<br>    #    (6)__len__方法：求类的长度<br>    def __len__(self):<br>        return len(self.data)<br>    <br>#-- 动态创建类type()<br>    # 一般创建类 需要在代码中提前定义<br>        class Hello(object):<br>            def hello(self, name='world'):<br>                print('Hello, %s.' % name)<br>        h = Hello()<br>        h.hello()                             # Hello, world<br>        type(Hello)                           # Hello是一个type类型 返回&lt;class 'type'&gt;<br>        type(h)                               # h是一个Hello类型 返回&lt;class 'Hello'&gt;<br>    # 动态类型语言中 类可以动态创建 type函数可用于创建新类型<br>        def fn(self, name='world'):           # 先定义函数<br>            print('Hello, %s.' % name)<br>        Hello = type('Hello', (object,), dict(hello=fn))    # 创建Hello类 type原型: type(name, bases, dict)<br>        h = Hello()                           # 此时的h和上边的h一致<br><br><br>"""异常相关----异常相关----异常相关----异常相关----异常相关----异常相关----异常相关----异常相关----异常相关----异常相关----异常相关----异常相关----异常相关"""<br>    <br>#-- #捕获异常: <br>        try:<br>        except:                               # 捕获所有的异常 等同于except Exception:<br>        except name:                          # 捕获指定的异常<br>        except name, value:                   # 捕获指定的异常和额外的数据(实例)<br>        except (name1, name2):<br>        except (name1, name2), value:<br>        except name4 as X:<br>        else:                                 # 如果没有发生异常<br>        finally:                              # 总会执行的部分<br>    # 引发异常: raise子句(raise IndexError)<br>        raise &lt;instance&gt;                      # raise instance of a class, raise IndexError()<br>        raise &lt;class&gt;                         # make and raise instance of a class, raise IndexError<br>        raise                                 # reraise the most recent exception<br><br>#-- Python3.x中的异常链: raise exception from otherException<br>    except Exception as X:<br>        raise IndexError('Bad') from X<br>        <br>#-- assert子句: assert &lt;test&gt;, &lt;data&gt;<br>    assert x &lt; 0, 'x must be negative'<br>    <br>#-- with/as环境管理器:作为常见的try/finally用法模式的替代方案<br>    with expression [as variable], expression [as variable]:<br>    # 例子:<br>        with open('test.txt') as myfile:<br>            for line in myfile: print(line)<br>    # 等同于:<br>        myfile = open('test.txt')<br>        try:<br>            for line in myfile: print(line)<br>        finally:<br>            myfile.close()<br><br>#-- 用户自定义异常: class Bad(Exception):.....<br>    """<br>    Exception超类 / except基类即可捕获到其所有子类<br>    Exception超类有默认的打印消息和状态 当然也可以定制打印显示:<br>    """<br>    class MyBad(Exception):<br>        def __str__(self):<br>            return '定制的打印消息'<br>    try:<br>        MyBad()<br>    except MyBad as x:<br>        print(x)<br>    <br>#-- 用户定制异常数据<br>    class FormatError(Exception):<br>        def __init__(self, line ,file):<br>            self.line = line<br>            self.file = file<br>    try:<br>        raise FormatError(42, 'test.py')<br>    except FormatError as X:<br>        print('Error at ', X.file, X.line)<br>    # 用户定制异常行为(方法):以记录日志为例<br>    class FormatError(Exception):<br>        logfile = 'formaterror.txt'<br>        def __init__(self, line ,file):<br>            self.line = line<br>            self.file = file<br>        def logger(self):<br>            open(self.logfile, 'a').write('Error at ', self.file, self.line)<br>    try:<br>        raise FormatError(42, 'test.py')<br>    except FormatError as X:<br>        X.logger()<br><br>#-- 关于sys.exc_info:允许一个异常处理器获取对最近引发的异常的访问<br>    try:<br>        ......<br>    except:<br>        # 此时sys.exc_info()返回一个元组(type, value, traceback)<br>        # type:正在处理的异常的异常类型<br>        # value:引发的异常的实例<br>        # traceback:堆栈信息<br>        <br>#-- 异常层次<br>    BaseException<br>    +-- SystemExit<br>    +-- KeyboardInterrupt<br>    +-- GeneratorExit<br>    +-- Exception<br>        +-- StopIteration<br>        +-- ArithmeticError<br>        +-- AssertionError<br>        +-- AttributeError<br>        +-- BufferError<br>        +-- EOFError<br>        +-- ImportError<br>        +-- LookupError<br>        +-- MemoryError<br>        +-- NameError<br>        +-- OSError<br>        +-- ReferenceError<br>        +-- RuntimeError<br>        +-- SyntaxError<br>        +-- SystemError<br>        +-- TypeError<br>        +-- ValueError<br>        +-- Warning<br><br>    <br>"""Unicode和字节字符串---Unicode和字节字符串----Unicode和字节字符串----Unicode和字节字符串----Unicode和字节字符串----Unicode和字节字符串----Unicode和字节字符串"""<br><br>#-- Python的字符串类型<br>    """Python2.x"""<br>    # 1.str表示8位文本和二进制数据<br>    # 2.unicode表示宽字符Unicode文本<br>    """Python3.x"""<br>    # 1.str表示Unicode文本（8位或者更宽）<br>    # 2.bytes表示不可变的二进制数据<br>    # 3.bytearray是一种可变的bytes类型<br><br>#-- 字符编码方法<br>    """ASCII"""                   # 一个字节，只包含英文字符，0到127，共128个字符，利用函数可以进行字符和数字的相互转换<br>    ord('a')                      # 字符a的ASCII码为97，所以这里返回97<br>    chr(97)                       # 和上边的过程相反，返回字符'a'<br>    """Latin-1"""                 # 一个字节，包含特殊字符，0到255，共256个字符，相当于对ASCII码的扩展<br>    chr(196)                      # 返回一个特殊字符：Ä<br>    """Unicode"""                 # 宽字符，一个字符包含多个字节，一般用于亚洲的字符集，比如中文有好几万字<br>    """UTF-8"""                   # 可变字节数，小于128的字符表示为单个字节，128到0X7FF之间的代码转换为两个字节，0X7FF以上的代码转换为3或4个字节<br>    # 注意：可以看出来，ASCII码是Latin-1和UTF-8的一个子集<br>    # 注意：utf-8是unicode的一种实现方式，unicode、gbk、gb2312是编码字符集<br>    <br>#-- 查看Python中的字符串编码名称，查看系统的编码<br>    import encodings<br>    help(encoding)<br>    import sys<br>    sys.platform                  # 'win64'<br>    sys.getdefaultencoding()      # 'utf-8'<br>    sys.getdefaultencoding()      # 返回当前系统平台的编码类型<br>    sys.getsizeof(object)         # 返回object占有的bytes的大小<br>    <br>#-- 源文件字符集编码声明: 添加注释来指定想要的编码形式 从而改变默认值 注释必须出现在脚本的第一行或者第二行<br>    """说明：其实这里只会检查#和coding:utf-8，其余的字符都是为了美观加上的"""<br>    # _*_ coding: utf-8 _*_<br>    # coding = utf-8<br>    <br>#-- #编码: 字符串 --&gt; 原始字节       #解码: 原始字节 --&gt; 字符串<br><br>#-- Python3.x中的字符串应用<br>    s = '...'                     # 构建一个str对象，不可变对象<br>    b = b'...'                    # 构建一个bytes对象，不可变对象<br>    s[0], b[0]                    # 返回('.', 113)<br>    s[1:], b[1:]                  # 返回('..', b'..')<br>    B = B"""<br>        xxxx<br>        yyyy<br>        """<br>    # B = b'\nxxxx\nyyyy\n'<br>    # 编码，将str字符串转化为其raw bytes形式：<br>        str.encode(encoding = 'utf-8', errors = 'strict')<br>        bytes(str, encoding)<br>    # 编码例子：<br>        S = 'egg'<br>        S.encode()                    # b'egg'<br>        bytes(S, encoding = 'ascii')  # b'egg'<br>    # 解码，将raw bytes字符串转化为str形式：<br>        bytes.decode(encoding = 'utf-8', errors = 'strict')<br>        str(bytes_or_buffer[, encoding[, errors]])<br>    # 解码例子：<br>        B = b'spam'<br>        B.decode()                # 'spam'<br>        str(B)                    # "b'spam'"，不带编码的str调用，结果为打印该bytes对象<br>        str(B, encoding = 'ascii')# 'spam'，带编码的str调用，结果为转化该bytes对象<br>    <br>#-- Python2.x的编码问题<br>    u = u'汉'<br>    print repr(u)                 # u'\xba\xba'<br>    s = u.encode('UTF-8')<br>    print repr(s)                 # '\xc2\xba\xc2\xba'<br>    u2 = s.decode('UTF-8')<br>    print repr(u2)                # u'\xba\xba'<br>    # 对unicode进行解码是错误的<br>    s2 = u.decode('UTF-8')        # UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)<br>    # 同样，对str进行编码也是错误的<br>    u2 = s.encode('UTF-8')        # UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)<br><br>#-- bytes对象<br>    B = b'abc'<br>    B = bytes('abc', 'ascii')<br>    B = bytes([97, 98, 99])<br>    B = 'abc'.encode()<br>    # bytes对象的方法调用基本和str类型一致 但:B[0]返回的是ASCII码值97, 而不是b'a'<br>    <br>#-- #文本文件: 根据Unicode编码来解释文件内容，要么是平台的默认编码，要么是指定的编码类型<br>    # 二进制文件：表示字节值的整数的一个序列 open('bin.txt', 'rb')<br>    <br>#-- Unicode文件<br>    s = 'A\xc4B\xe8C'             # s = 'A?BèC'  len(s) = 5<br>    #手动编码<br>        l = s.encode('latin-1')   # l = b'A\xc4B\xe8C'  len(l) = 5<br>        u = s.encode('utf-8')     # u = b'A\xc3\x84B\xc3\xa8C'  len(u) = 7<br>    #文件输出编码<br>        open('latindata', 'w', encoding = 'latin-1').write(s)<br>        l = open('latindata', 'rb').read()                        # l = b'A\xc4B\xe8C'  len(l) = 5<br>        open('uft8data', 'w', encoding = 'utf-8').write(s)<br>        u = open('uft8data', 'rb').read()                         # u = b'A\xc3\x84B\xc3\xa8C'  len(u) = 7<br>    #文件输入编码<br>        s = open('latindata', 'r', encoding = 'latin-1').read()   # s = 'A?BèC'  len(s) = 5<br>        s = open('latindata', 'rb').read().decode('latin-1')      # s = 'A?BèC'  len(s) = 5<br>        s = open('utf8data', 'r', encoding = 'utf-8').read()      # s = 'A?BèC'  len(s) = 5<br>        s = open('utf8data', 'rb').read().decode('utf-8')         # s = 'A?BèC'  len(s) = 5<br>        <br><br>"""其他----其他----其他----其他----其他----其他----其他----其他----其他----其他----其他----其他----其他----其他----其他----其他----其他----其他----其他"""<br><br>#-- Python实现任意深度的赋值 例如a[0] = 'value1'; a[1][2] = 'value2'; a[3][4][5] = 'value3'<br>    class MyDict(dict):<br>        def __setitem__(self, key, value):                 # 该函数不做任何改动 这里只是为了输出<br>            print('setitem:', key, value, self)<br>            super().__setitem__(key, value)<br>        def __getitem__(self, item):                       # 主要技巧在该函数<br>            print('getitem:', item, self)                  # 输出信息<br>            # 基本思路: a[1][2]赋值时 需要先取出a[1] 然后给a[1]的[2]赋值<br>            if item not in self:                           # 如果a[1]不存在 则需要新建一个dict 并使得a[1] = dict<br>                temp = MyDict()                            # 新建的dict: temp<br>                super().__setitem__(item, temp)            # 赋值a[1] = temp<br>                return temp                                # 返回temp 使得temp[2] = value有效<br>            return super().__getitem__(item)               # 如果a[1]存在 则直接返回a[1]<br>    # 例子:<br>        test = MyDict()<br>        test[0] = 'test'<br>        print(test[0])<br>        test[1][2] = 'test1'<br>        print(test[1][2])<br>        test[1][3] = 'test2'<br>        print(test[1][3])<br><br>#-- Python中的多维数组<br>    lists = [0] * 3                                        # 扩展list，结果为[0, 0, 0]<br>    lists = [[]] * 3                                       # 多维数组，结果为[[], [], []]，但有问题，往下看<br>    lists[0].append(3)                                     # 期望看到的结果[[3], [], []]，实际结果[[3], [3], [3]]，原因：list*n操作，是浅拷贝，如何避免？往下看<br>    lists = [[] for i in range(3)]                         # 多维数组，结果为[[], [], []]<br>    lists[0].append(3)                                     # 结果为[[3], [], []]<br>    lists[1].append(6)                                     # 结果为[[3], [6], []]<br>    lists[2].append(9)                                     # 结果为[[3], [6], [9]]<br>    lists = [[[] for j in range(4)] for i in range(3)]     # 3行4列，且每一个元素为[]<br></code></pre></div></td></tr></table></figure>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Python/">Python</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2018/09/26/Python初始面对对象(1)/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Python:初始面对对象(1)</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2018/09/20/python内置函数filter，map，lambda,递归/">
                        <span class="hidden-mobile">python内置函数filter，map，lambda,递归</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                

              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
